<!-- 书城 -->

<template>
  <div class="find">
    <book-item v-for="n in 10" :key="n"/>
    <tab-bar></tab-bar>
  </div>
</template>

<script>
import TabBar from "@/components/base/tab-bar/tab-bar";
import TypesItem from "@/components/base/types-item/types-item";
import CrossLine from "@/components/base/cross-line/cross-line";
import TitleBar from "@/components/base/title-bar/title-bar";
import BookItem from "@/components/base/book-item/book-item";
// import axios from 'axios'
import Parse from "parse";

export default {
  components: {
    TabBar,
    TypesItem,
    CrossLine,
    TitleBar,
    BookItem
  },
  data() {
    return {
      goodsCategory: [],
      sugGoods: [],
      goods: [],
      goodsCache: {},
      // 需要传入详情页的商品
      selectedFood: {},
      selected: null,
      allLoaded: false
    };
  },
  props: {},
  watch: {},
  methods: {
    loadBottom() {
      var cache = this.goodsCache[this.selected];
      if (cache && cache.query) {
        cache
          .skip(cache.goods.length)
          .query.find()
          .then(data => {
            data.forEach(v => {
              var d = {
                id: v.id,
                picUrl: v.get("picUrl"),
                goodsName: v.get("goodsName"),
                goodsDesc: v.get("goodsDesc"),
                goodsUnit: v.get("goodsUnit"),
                salePrice: v.get("salePrice"),
                sellVolumn: v.get("sellVolumn")
              };
              this.goods.push(d);
              cache.goods.push(d);
            });
            cache.allLoaded = !!data.length;
            this.$refs.loadmore.onBottomLoaded();
          });
      }
    },
    goMore(id) {
      this.$router.push(`/product_list/${id}`);
    },
    // 初始化列表数据
    _initIndexListData() {
      var Topic = Parse.Object.extend("Topic");
      var query = new Parse.Query(Topic);
      query
        .addAscending("sortOrder")
        .equalTo("isShow", true)
        .find()
        .then(data => {
          for (var i = 0; i < data.length; i++) {
            var v = data[i];
            var result = {
              id: v.id,
              picUrl: v.get("picUrl"),
              title: v.get("title")
            };
            this.__getIndexList(result, v, i);
            this.sugGoods.push(result);
          }
        });
    }
  },
  filters: {},
  computed: {},
  created() {
    // 初始化列表数据
    this._initIndexListData();
  },
  mounted() {},
  destroyed() {}
};
</script>

<style lang="scss" scoped>
@import "~@/assets/scss/const.scss";
@import "~@/assets/scss/mixin.scss";

.find {
  background: $app-background-color;
  padding-bottom: 50px;
}
</style>
